import openai
from args import *
import openai
from args import *

from flask import Flask, request, jsonify
from flask import Flask
import json
from prompts import *
from flask_cors import CORS, cross_origin
app = Flask(__name__)
app.debug = False
client = openai.Client(
  api_key="cannot be empty",
  base_url=f"http://{xinference_url}:{xinference_port}/v1"
)

def wrap_request(data_list:list[str]):
  response = client.embeddings.create(
    model="t_bge-small-zh-v1.5",
    input=data_list
  )
  data = response.data
  data = [list(d)[0][1] for d in data]
  return data

@app.route('/model/extract/vector', methods=['post'])
@cross_origin()
def post_http_domains():
    req = request.get_json()
    data = req.get('data', [])
    ret = wrap_request(data)
    return jsonify({
      "code": 200,
      "data": ret,
      "message": "success"
    })


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=6003)
    # 这里指定了地址和端口号。也可以不指定地址填0.0.0.0那么就会使用本机地址ip